package valutatore;
import java.math.BigDecimal;
import token.Token.Type;

public class AssignExpr extends Expr {
	private Ident id;
	private Type oper;
	private Expr expr;

	public AssignExpr(Ident id, Type oper, Expr expr) {
		this.id = id;
		this.oper = oper;
		this.expr = expr;
	}

	public static AssignExpr _(Ident id, Type oper, Expr val) {
		return new AssignExpr(id, oper, val);
	}

	@Override
	public Value eval(Env env) {
		switch (oper) {
		case Becomes:
			return env.setValue(id, expr.eval(env));
		case PlusBecomes:
			return env.setValue(id, id.eval(env).plus(expr.eval(env)));
		case MinusBecomes:
			return env.setValue(id, id.eval(env).minus(expr.eval(env)));
		case TimesBecomes:
			return env.setValue(id, id.eval(env).times(expr.eval(env)));
		case DivBecomes:
			return env.setValue(id, id.eval(env).div(expr.eval(env)));
		case PowBecomes:
			return env.setValue(id, id.eval(env).pow(expr.eval(env)));//.intValue()));
		default:
			return null;
		}
	}

}
